<?php

/* @var $this \yii\web\View */
/* @var $content string */

use backend\assets\AppAsset;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\helpers\VarDumper;
use yii\widgets\Breadcrumbs;
use common\widgets\Alert;

AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
    <meta charset="<?= Yii::$app->charset ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?= Html::csrfMetaTags() ?>
    <title><?= Html::encode($this->title) ?></title>
    <?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>

<div class="wrap">
    <?php
    NavBar::begin([
        'brandLabel' => 'JINGXI SITE',
        'brandUrl' => Yii::$app->homeUrl,
        'options' => [
            'class' => 'navbar-inverse navbar-fixed-top',
        ],
    ]);

    $menuItems = [
        ['label' => 'Home', 'url' => ['/site/index']],
        ['label' => '注册&nbsp;'.Html::tag('span',' ',['class'=>'glyphicon glyphicon-user']),
            'url' => ['/manager/signup'],
            'options'=>[
                    //可以把属性添加到li标签上
                    'title'=>'注册',
            ]
        ],
    ];
/*
    $itemscontent = [
        [
            'label'=>Html::tag('span',' ',['class'=>'glyphicon glyphicon-th-list']).' &nbsp;内容管理',
            'items'=>[
//                        '<li class="divider list-group-item"></li>',
                ['label'=>'当前页面','url'=>\yii\helpers\Url::current(),'options'=>['class'=>' list-group-item'],],
                ['label'=>'商标管理','url'=>['brand/index'],'options'=>['class'=>' list-group-item'],],
                ['label'=>'文章分类管理','url'=>['article-category/index'],'options'=>['class'=>' list-group-item'],],
                ['label'=>'文章管理 list-group','url'=>['article/index'],'options'=>['class'=>' list-group-item'],],
                ['label'=>'商品分类管理','url'=>['goods-category/index'],'options'=>['class'=>' list-group-item'],],
                ['label'=>'商品管理','url'=>['goods/index'],'options'=>['class'=>' list-group-item'],],
                ['label'=>'site管理','url'=>['site/index'],'options'=>['class'=>' list-group-item'],],
                ['label'=>'管理员管理',
                    'items'=>[
                        ['label'=>'site管理','url'=>['site/index'],'options'=>['class'=>' list-group-item'],],
                    ],
                    ],

            ],
        ]
    ];*/

    $itemscontent = [];
    if (Yii::$app->user->isGuest) {
        $menuItems[] = [
            'label' => Html::tag('span',' ',['class'=>'glyphicon glyphicon-log-in']),
            'url' => ['/manager/login'],
            'options'=>[
                'title'=>'登录',
            ]
        ];
    } else {
        //登录成功过后调用方法生成菜单
        /** @var  $identity backend\models\Admin */
        $identity=\Yii::$app->user->identity;
        $itemscontent = $identity->generateMenu();
        //var_dump($itemscontent);exit;
        $menuItems[] = '<li title="注销">'
            . Html::beginForm(['/manager/logout'], 'post')
            . Html::submitButton(
                  Yii::$app->user->identity->username.'&nbsp;'.Html::tag('span',' ',['class'=>'glyphicon glyphicon-log-out']),
                [
                    'class' => 'btn btn-link logout',
                    'title'=>'注销',
                ]
            )
            . Html::endForm()
            . '</li>';
    }

    echo Nav::widget([
        'options' => ['class' => 'navbar-nav navbar-right'],
        'items' => ArrayHelper::merge($itemscontent,$menuItems),
        'encodeLabels'=>false,
    ]);


    NavBar::end();
    ?>

    <div class="container">
        <?= Breadcrumbs::widget([
            'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
        ]) ?>
        <?= Alert::widget() ?>
        <?= $content ?>
    </div>
</div>

<footer class="footer">
    <div class="container">
        <p class="pull-left">&copy; 京西 网站 <?= date('Y') ?></p>

        <p class="pull-right"><?= Yii::powered() ?></p>
    </div>
</footer>

<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
